﻿using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Management;
using System.Security.Cryptography;
using System.Text;
using Meqs.Entity;

/// <summary>
/// LoginCommon 的摘要说明
/// </summary>
public class LoginCommon
{
    public LoginCommon()
    {

    }
   
    /// <summary>
    /// 加密
    /// </summary>
    /// <param name="sn"></param>
    /// <param name="pc"></param>
    /// <returns></returns>
    public static string Encrypt(string sn, string pc)
    {
        string s = "";
        string p = "";
        if (!string.IsNullOrEmpty(sn))
        {
            s = sn.Trim();
        }
        if (!string.IsNullOrEmpty(pc))
        {
            p = pc.Trim();
        }
        return UserMd5(s + p);
    }
    //MD5加密
    //参数:待加密字符串
    //返回:加密后的字符串

    public static string UserMd5(string str)
    {
        string cl = str;
        string pwd = "";
        MD5 md5 = MD5.Create();//实例化一个md5对像
        // 加密后是一个字节类型的数组，这里要注意编码UTF8/Unicode等的选择　
        byte[] s = md5.ComputeHash(Encoding.Default.GetBytes(cl));
        // 通过使用循环，将字节类型的数组转换为字符串，此字符串是常规字符格式化所得

        for (int i = 0; i < s.Length; i++)
        {
            // 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母，如果使用大写（X）则格式后的字符是大写字符 

            pwd = pwd + s[i].ToString("X2");

        }
        return pwd;
    }
    /// <summary>
    /// 取得网卡mac地址
    /// </summary>
    /// <returns></returns>
    public static String GetMacAddress()
    {
        ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
        ManagementObjectCollection moc = mc.GetInstances();
        string MacAddress = "";

        foreach (ManagementObject mo in moc)
        {
            if ((bool)mo["IPEnabled"] == true)
            {
                MacAddress += mo["MacAddress"].ToString();
            }
            mo.Dispose();
        }
        return MacAddress;
    }

    
}
